package com.itheima.Advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//@Aspect
@Component
public class TimeAdvice {
    @Pointcut("execution(* com.itheima.dao.BookDao.save(..))")
    public void pt() {
    }

    @Around("TimeAdvice.pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //获取执行的签名对象
        Signature signature = pjp.getSignature();
        //获取接口或类的全限定名
        String className = signature.getDeclaringTypeName();
        //获取方法名
        String methodName = signature.getName();
        //消息通知，开始时间
        long startTime = System.currentTimeMillis();
        //万次执行任务
        for (int i = 0; i < 10000; i++) {
            pjp.proceed();
        }
        //结束时间
        long endTime = System.currentTimeMillis();
        //打印执行结果
        System.out.println("执行路径" + className + "方法名" + methodName + "万次执行效率时间" + (endTime - startTime) + "ms");
        return null;
    }
}
